package com.one.common.common.system;

import com.one.common.common.system.model.param.QiNiuParam;
import com.one.common.common.system.model.param.UpdateVersionParam;
import com.one.common.common.system.model.param.UploadGpsParam;
import com.one.common.common.system.model.response.BannerResponse;
import com.one.common.common.system.model.response.DefaultResponse;
import com.one.common.common.system.model.response.OrderStateResponse;
import com.one.common.common.system.model.response.QiNiuTokenResponse;
import com.one.common.common.system.model.response.SessionResponse;
import com.one.common.common.system.model.response.UpdateVersionResponse;
import com.one.common.config.CMemoryData;
import com.one.common.config.MyContact;
import com.one.common.model.http.base.BaseModel;
import com.one.common.model.http.callback.ObserverOnNextListener;
import com.one.common.model.http.callback.ObserverOnResultListener;
import com.one.common.view.base.BaseActivity;

import static com.one.common.common.system.SystemApi.GET_BANNER;
import static com.one.common.common.system.SystemApi.GET_MODIFYMOBILE_QINIU_TOKEN;
import static com.one.common.common.system.SystemApi.GET_ORDER_STATE;
import static com.one.common.common.system.SystemApi.GET_QINIU_TOKEN;
import static com.one.common.common.system.SystemApi.GET_SESSION;
import static com.one.common.common.system.SystemApi.UPDATE_VERSION;
import static com.one.common.common.system.SystemApi.UPLOAD_GPS;

/**
 * Author: zhulunjun
 * Email: zhulunjun@qq.com
 * CreateDate: 2018/11/20 11:03
 * Description：系统接口管理
 **/
public class SystemModel extends BaseModel<SystemApi> {

    public SystemModel(BaseActivity mActivity) {
        super(SystemApi.class, mActivity);
    }

    public SystemModel() {
        super(SystemApi.class);
    }

    /**
     * 获取session
     */
    public void getSession(ObserverOnNextListener<SessionResponse> listener) {
        mParam = getParams(GET_SESSION);
        handleOnNextObserverNoActivity(mApiService.getSession(mParam), listener);
    }

    /**
     * 获取七牛的token
     */
    public void getQiNiuToken(String type, ObserverOnNextListener<QiNiuTokenResponse> listener) {
        mParam = getParams(GET_QINIU_TOKEN, new QiNiuParam(type));
        handleOnNextObserverNoActivity(mApiService.getQiNiuToken(mParam), listener);
    }

    public void getQiNiuTokenModifyMobile(String type, ObserverOnNextListener<QiNiuTokenResponse> listener) {
        mParam = getParams(GET_MODIFYMOBILE_QINIU_TOKEN, new QiNiuParam(type));
        handleOnNextObserverNoActivity(mApiService.getQiNiuTokenModifyMobile(mParam), listener);
    }
    /**
     * 获取首页banner
     */
    public void getBanner(ObserverOnNextListener<BannerResponse> listener) {
        mParam = getParams(GET_BANNER);
        handleOnNextObserver(mApiService.getBanner(mParam), listener, false);
    }

    /**
     * 获取版本更新
     */
    public void updateVersion(ObserverOnResultListener<UpdateVersionResponse> listener) {
        UpdateVersionParam param = new UpdateVersionParam();
        if(CMemoryData.getAppSorce().equals(MyContact.CAR)){
            param.setInno_version(MyContact.CAR_VERSION);
        } else if(CMemoryData.getAppSorce().equals(MyContact.GOODS)){
            param.setInno_version(MyContact.GOODS_VERSION);
        } else if(CMemoryData.getAppSorce().equals(MyContact.DRIVER)){
            param.setInno_version(MyContact.DRIVER_VERSION);
        }
        mParam = getParams(UPDATE_VERSION, param);
        handleOnResultObserverNoActivity(mApiService.updateVersion(mParam), listener);
    }
    /**
     * 上传定位信息
     */
    public void uploadGps(UploadGpsParam param, ObserverOnNextListener<DefaultResponse> listener) {
        mParam = getParams(UPLOAD_GPS, param);
        handleOnNextObserverNoActivity(mApiService.uploadGps(mParam), listener);
    }

    /**
     * 查询是否存在运输中的订单
     */
    public void getOrderState(ObserverOnNextListener<OrderStateResponse> listener) {
        mParam = getParams(GET_ORDER_STATE);
        handleOnNextObserverNoActivity(mApiService.getOrderState(mParam), listener);
    }
}
